import safeData from '@/components/fieldTestManage/safeList';
import loading from '@/components/xuan-loading/xuan-loading.vue';

import {
	log
} from 'util'

export default {

	data() {
		return {
			// 加载
			width: '150rpx',
			height: '100rpx',
			shadeShow: true,
			backgroundColor: "transparent",
			pagesItem: {
				page: 1,
				pageSize: 20,
			},
			pageTotal: null,
			Inv: 0,
			datasList: {
				fCompanyid: "", // 左侧选中组织机构id
				page: 1, // 当前页码
				pageSize: 20, // 每页显示条数
				userId: "", // 查询待办或已办时传 列表页查询不传
				modelType: "0", // 0-待办 1-已办 传2 表示列表页查询  传3表示内嵌查询
				startDates: "", //取样日期开始时间
				endDates: "", //取样日期结束时间
				keyType: "", // 检测类型
				taskNumber: "", // 委托编号
				fProjectposition: "", //工程部位
				taskNo: "",
			},

			// 加载
			width: '150rpx',
			height: '100rpx',
			shadeShow: true,
			backgroundColor: "transparent",
			// 加载

			// num: 0,
			userInfo: null,
			//列表数据
			unSubmitData: [],
		}
	},
	components: {
		safeData,
		loading,
	},
	onShow() {
		var that = this
		if (this.Inv == 0) {
			setTimeout(() => {
				that.unsubmit()
			}, 300)
		}
		if (this.Inv == 1) {
			setTimeout(() => {
				that.submit()
			}, 300)
		}

	},
	onLoad(option) {
		var that = this;
		uni.getStorage({ //监督检查方式
			key: 'userInfo',
			success: function(res) {
				if (option.Inv) {
					that.Inv = option.Inv
				}
				that.userInfo = JSON.parse(res.data);
				that.getListData(that.Inv.toString());
			}
		});
	},


	onBackPress(event) {
		uni.switchTab({
			url: '/pages/home/index'
		});
		return true;
	},
	onNavigationBarButtonTap(e) {
		if (this.userInfo.companyNature == "施工单位" || this.userInfo.companyNature == "中心试验室") {
			uni.navigateTo({
				url: '/pages/apply/fieldTestManage/fieldPilesDetectedData/inter/index?type=' + 'add'
			});
			return true;
		} else {
			uni.showToast({
				title: "您暂无此权限",
				icon: 'none',
				duration: 2000
			});
		}
	},
	onReachBottom() {
		if (this.pagesItem.page >= this.pageTotal) return
		this.pagesItem.page++
		this.getListData();
	},
	methods: {
		// 跳详情页
		safeDetail(e) {
			if (e.Inv == 0) {
				uni.navigateTo({
					url: "/pages/apply/fieldTestManage/fieldPilesDetectedData/inter/index?id=" + e.id
				});
				return false;
			} else if (e.Inv == 1) {
				uni.navigateTo({
					url: "/pages/apply/fieldTestManage/fieldPilesDetectedData/submit/index?id=" + e.id
				});
				return false;
			}
		},
		// 跳详情页
		
		submit() {
			var that = this
			this.Inv = 1;
			this.unSubmitData = [];
			this.pagesItem.page = 1;
			this.getListData();
		},
		unsubmit() {
			var that = this
			this.Inv = 0;
			this.unSubmitData = [];
			this.pagesItem.page = 1;
			this.getListData();
		},

		getListData(num) {
			var that = this;
			let obj = {
				fCompanyid: that.userInfo.companyId, // 左侧选中组织机构id
				page: 1, // 当前页码
				pageSize: 20, // 每页显示条数
				userId: that.userInfo.userId, // 查询待办或已办时传 列表页查询不传
				modelType: that.Inv.toString(),
				startDates: "", //进场开始时间
				endDates: "", //进场结束时间
				taskNo: "",
				keyType: "桩基检测", //上方查询条件材料种类
				fProjectposition: "", //工程部位		
				fNote: "1", //旧外业1  新外业2
			}
			// this.$refs.loadings.open();
			this.$http.getFieldtestCheckTaskPageList(obj).then(res => {
				if (res.errcode == 0) {
					// console.log("列表", res)
					that.pageTotal = res.data.pageInfo.pages;
					that.unSubmitData = [...that.unSubmitData, ...res.data.pageInfo.list];
					// this.$refs.loadings.close();
				} else {
					uni.showToast({
						title: "获取数据失败",
						icon: 'none',
						duration: 2000
					});
					// this.$refs.loadings.close();
				}
			}, (err) => {
				uni.showToast({
					title: "获取数据失败",
					icon: 'none',
					duration: 2000
				});
				this.$refs.loadings.close();
			});
		},

		callback() {

		},
	}
}
